#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：spider 
@File    ：04_thread_safe.py
@Author  ：precedence
@Date    ：2025/11/8 06:14 
'''
import threading

many = 0


def work():
    global many
    for i in range(100):
        many += 1
        print(f'working--- {i}: {many}')


def cost():
    global many
    for i in range(100):
        many -= 1
        print(f'cost--- {i}: {many}')


working_days = 1000
threads = []
for i in range(working_days):
    t = threading.Thread(target=work)
    threads.append(t)
    t.start()
for i in range(working_days):
    t = threading.Thread(target=cost)
    threads.append(t)
    t.start()
for t in threads:
    t.join()
print(f"result:{many}")
